Life cycle of an App 生命週期
@UIApplicationMain
,並產生元件UIApplication
。@UIApplicationMain
及UIApplication
為了解決問題,會去訪問服從協定UIApplicationDelegate
的物件。@UIApplicationMain
也會讀取info.plist
檔案,用以確認Main.storyboard
及LaunchScreen
的安排,並作出/啟動畫面。UIWindow
→Launch Screen
→view fromViewController
。理論如上,來看看AppDelegate.swift在做什麼吧
開始執行程式的地方
@UIApplicationMain
程式啟動後要做什麼事?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
app即將離開時執行的程式碼
Point:記錄使用者想保存的資訊,並於重新執行程式時顯示
func applicationWillResignActive(_ application: UIApplication)
app進入背景時執行的程式碼
func applicationDidEnterBackground(_ application: UIApplication)
app即將顯示於螢幕前所執行的程式碼
func applicationWillEnterForeground(_ application: UIApplication)
app已執行後所執行的程式碼
func applicationDidBecomeActive(_ application: UIApplication)
app要被關閉時所執行的程式碼
func applicationWillTerminate(_ application: UIApplication)